<?php
include("session.php");
include("config.php");

if ($_SESSION['userlevel'] < LEVEL_EDIT_USER || $_SESSION['userlevel'] < LEVEL_CREATE_USER)
    handle_levelviolation("user_list.php", $db, "maintime.php");
?>
<html>

<head>
    <title>Easy Time Tracker</title>
    <link rel="stylesheet" href="/timetracker.css" type="text/css" media="screen" />
</head>

<body>
    <div class="Border" align="center">
        <h3><?php ELang("user"); ?></h3> <?php if ($_SESSION['userlevel'] >= LEVEL_CREATE_USER) printf("<a class='tooltip' href='edit_user.php?id=-1'><img src='icons/22/list-add.png'>
        <div class='rtooltiptext'>%s %s</div></a>", RLang("create_new"), RLang("user")) ?>
        <table class="Datatable">
            <tr>
                <th><?php ELang("name"); ?></th>
                <th><?php ELang("level"); ?></th>
                <th><?php ELang("created"); ?></th>
                <th><img src="icons/22/document-encrypt.png"></th>
                <th><img src="icons/22/document-edit.png"></th>
            </tr>
            <?php

            $sql = "SELECT * FROM user";
            if (!$result = get_db_result($db, $sql, null)) {
                echo ($sql . " ");
                die(mysqli_error($db));
            }
            $rowcnt = mysqli_num_rows($result);
            for ($i = 0; $i < $rowcnt; $i++) {
                $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
                printf("<tr><td>%s</td><td>%u</td><td>%s</td>", $row['name'], $row['level'], $row['created']);
                if ($row['level'] > 0)
                    printf("<td><a class='tooltip' href='retire_user.php?id=%u'><img src='icons/22/document-encrypt.png'><div class='ltooltiptext'>%s</div></a></td>", $row['id'], RLang("retireuser"));
                else
                    echo ("<td></td>");

                printf("<td><a class='tooltip' href='edit_user.php?id=%u'><img src='icons/22/document-edit.png'><div class='ltooltiptext'>%s</div></a></td></tr>\r\n", $row['id'], RLang("edituser"));
            }
            ?>
        </table>
        <a href='maintime.php' class='tooltip'><img src='icons/22/edit-undo.png'>
            <div class='rtooltiptext'><?php ELang("back"); ?></div>
        </a>
        <div>
            <p>
                <?php printMSG(); ?>
            </p>

</body>